package dy

import (
	"context"
	v1 "dy_spider/api/dy/v1"
	"dy_spider/internal/dao"
	"fmt"
)

func (s *sDy) PostLive(ctx context.Context, req *v1.PostLiveReq) (res *v1.PostLiveRes, err error) {
	data := map[string]string{
		"live_id":   req.LiveId,
		"live_name": req.LiveName,
	}
	fmt.Println(data)
	_, err = dao.DyLive.Ctx(ctx).Save(data)
	if err != nil {
		return nil, err
	}
	return res, nil
}

func (s *sDy) GetUnBoundLive(ctx context.Context, req *v1.GetUnBoundLiveReq) (res *v1.GetUnBoundLiveRes, err error) {
	res = new(v1.GetUnBoundLiveRes)
	one, err := dao.DyMsg.Ctx(ctx).Distinct().Fields("live_id").
		WhereNotIn("live_id", dao.DyLive.Ctx(ctx).Fields("live_id")).One()
	if err != nil {
		return nil, err
	}
	res.LiveId = one["live_id"].String()
	return
}
